set :application, "radius"
require 'bundler/capistrano'                
require "delayed/recipes"  

set :rvm_type, :system 
require 'rvm/capistrano'

set :stages, %w(staging production)
set :default_stage, "staging"
require 'capistrano/ext/multistage'

set :user, "rails"  # ssh user 

# ssh to the deploy server
default_run_options[:pty] = true  # Must be set for the password prompt

set :repository, "git@git.oschina.net:sdutlinux/radius-web.git"
set :deploy_via, :remote_cache
set :scm_username, 'lidashuang'
set :scm, :git
set :git_shallow_clone, 1
ssh_options[:forward_agent] = true

# set gems
set :bundle_without, [:development,:test]

after "deploy:restart", "deploy:cleanup"

after "deploy:stop",    "delayed_job:stop"
after "deploy:start",   "delayed_job:start"
after "deploy:restart", "delayed_job:restart"

set :delayed_job_command, "bin/delayed_job"

namespace :deploy do
  task :start do 
    run "cd #{current_path}; bundle exec thin start -C /home/rails/#{application}.yml"
  end

  task :stop do 
    run "cd #{current_path}; bundle exec thin stop -C /home/rails/#{application}.yml"
  end

  task :restart, :roles => :app, :except => { :no_release => true } do
    run "cd #{current_path}; bundle exec thin restart -C /home/rails/#{application}.yml"
  end

#  task :config_file do
#    #run "ln -s  #{shared_path}/database.yml #{release_path}/config/database.yml"
#  end

end
